home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Pentominoes 1.4.1 / source / Pentominoes ƒ / Pent code / pent files.c next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  4.4 KB  |  171 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        pent files.c
  4.  
  5. Purpose:    This module handles the standard file dialogs for getting
  6.             saved games and saving current games.
  7.  
  8.  
  9. Pentominoes - a 2-D geometry board game
  10. Copyright (C) 1993 Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "Script.h"
  30. #include "pent files.h"
  31. #include "pent load-save.h"
  32. #include "msg graphics.h"
  33. #include "msg environment.h"
  34.  
  35. Boolean GetSourceFile(FSSpec *gameFile, Boolean AllOfEm, Boolean useOldGame)
  36. {
  37.     Point                where;
  38.     OSErr                isHuman;
  39.     StandardFileReply    reply;
  40.     SFReply                oldReply;
  41.     unsigned int        count;
  42.     SFTypeList            typeList;
  43.     FInfo                fndrInfo;
  44.     long                procID;
  45.     int                    i;
  46.     
  47.     typeList[0]='PBrd';
  48.     isHuman=FALSE;
  49.     if ((gStandardFile58) && (!useOldGame))
  50.     {
  51.         if (AllOfEm)
  52.             StandardGetFile(0L, -1, 0L, &reply);
  53.         else
  54.             StandardGetFile(0L, 1, typeList, &reply);
  55.     }
  56.     else
  57.     {
  58.         where.h = (gMainScreenBounds.right - 348)/2;
  59.         where.v = (gMainScreenBounds.bottom - 200)/3;
  60.         if (AllOfEm)
  61.             SFGetFile(where, "\p", 0L, -1, 0L, 0L, &oldReply);
  62.         else
  63.             SFGetFile(where, "\p", 0L, 3, typeList, 0L, &oldReply);
  64.         
  65.         reply.sfGood = oldReply.good;
  66.         if (reply.sfGood)
  67.         {
  68.             reply.sfType = oldReply.fType;
  69.             isHuman=GetWDInfo(oldReply.vRefNum, &reply.sfFile.vRefNum,
  70.                                 &reply.sfFile.parID, &procID);
  71.             if (isHuman!=noErr)
  72.             {
  73.                 reply.sfFile.vRefNum = oldReply.vRefNum;
  74.                 reply.sfFile.parID = 0;
  75.             }
  76.             count=oldReply.fName[0];
  77.             for (i=0; i<=count; i++)
  78.                 reply.sfFile.name[i]=oldReply.fName[i];
  79.             
  80.             reply.sfScript=smSystemScript;
  81.             isHuman=HGetFInfo(reply.sfFile.vRefNum, reply.sfFile.parID,
  82.                                 reply.sfFile.name, &fndrInfo);
  83.             reply.sfFlags=(isHuman==noErr) ? fndrInfo.fdFlags : 0;
  84.             
  85.             reply.sfIsFolder=FALSE;
  86.             reply.sfIsVolume=FALSE;
  87.         }
  88.     }
  89.  
  90.     if ((reply.sfGood) && (!isHuman))
  91.         MyMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name,
  92.                             gameFile);
  93.         
  94.     return ((reply.sfGood) && (!isHuman));
  95. }
  96.  
  97. Boolean GetDestFile(FSSpec *gameFile, Boolean *deleteTheThing, Boolean isRealGame)
  98. {
  99.     unsigned int        count;
  100.     Str255                otherName;
  101.     StandardFileReply    reply;
  102.     SFReply                oldReply;
  103.     Point                where;
  104.     FInfo                fndrInfo;
  105.     long                procID;
  106.     OSErr                isHuman;
  107.     int                    i;
  108.         
  109.     if (gStandardFile58)
  110.         if (isRealGame)
  111.             StandardPutFile("\pSave Pentominoes game as...", "\p", &reply);
  112.         else
  113.             StandardPutFile("\pSave Pentominoes solution...", "\p", &reply);
  114.     else
  115.     {
  116.         where.h = (gMainScreenBounds.right - 304)/2;
  117.         where.v = (gMainScreenBounds.bottom - 184)/3;
  118.         if (isRealGame)
  119.             SFPutFile(where, "\pSave Pentominoes game as...", "\p", 0, &oldReply);
  120.         else
  121.             SFPutFile(where, "\pSave Pentominoes solution...", "\p", 0, &oldReply);
  122.         reply.sfGood = oldReply.good;
  123.         if (reply.sfGood)
  124.         {
  125.             isHuman=GetWDInfo(oldReply.vRefNum, &reply.sfFile.vRefNum,
  126.                                 &reply.sfFile.parID, &procID);
  127.             if (isHuman!=noErr)
  128.             {
  129.                 reply.sfFile.vRefNum = oldReply.vRefNum;
  130.                 reply.sfFile.parID = 0;
  131.             }            
  132.             count=oldReply.fName[0];
  133.             for (i=0; i<=count; i++)
  134.                 reply.sfFile.name[i]=oldReply.fName[i];
  135.             
  136.             reply.sfScript = smSystemScript;
  137.             isHuman=HGetFInfo(reply.sfFile.vRefNum, reply.sfFile.parID,
  138.                                 reply.sfFile.name, &fndrInfo);
  139.             reply.sfReplacing=(isHuman!=fnfErr);
  140.             
  141.             reply.sfIsFolder=FALSE;
  142.             reply.sfIsVolume=FALSE;
  143.         }
  144.     }
  145.  
  146.     if (reply.sfGood)
  147.     {
  148.         *deleteTheThing=reply.sfReplacing;    
  149.         MyMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name,
  150.                         gameFile);
  151.     }
  152.     
  153.     return (reply.sfGood);
  154. }
  155.  
  156. pascal OSErr MyMakeFSSpec(short vRefNum, long parID, ConstStr255Param fileName,
  157.     FSSpecPtr myFSS)
  158. {
  159.     int            i;
  160.     
  161.     if (gHasFSSpecs)
  162.         FSMakeFSSpec(vRefNum, parID, fileName, myFSS);
  163.     else
  164.     {
  165.         myFSS->vRefNum=vRefNum;
  166.         myFSS->parID=parID;
  167.         for (i=fileName[0]; i>=0; i--)
  168.             myFSS->name[i]=fileName[i];
  169.     }
  170. }
  171.